package com.sl.au.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.sl.au.entity.*;
import com.sl.au.repository.*;
import com.sl.au.service.PartsAttributesService;

@Service("PartsAttributesService")
@Transactional
public class PartsAttributesServiceImpl extends BaseServiceImpl implements PartsAttributesService {
	@Autowired
	PartsAttributesRepository partsAttributesRepository;

	@Override
	public PartsAttributesRepository getRepository() {
		// TODO Auto-generated method stub
		return this.partsAttributesRepository;
	}

	@Override
	public List<PartsAttributes> getPartsAttributes(int start, int length, String key, String orderName, String dir) {
		Page<PartsAttributes> pages = null;
		Pageable pageable = new PageRequest(start / length, length, Sort.Direction.DESC, "itemOrder");
		if (StringUtils.hasText(key)) {
			String id="";
			pages = partsAttributesRepository.findPartsAttributes(id , key, pageable);
		} else {
			pages = partsAttributesRepository.findAll(pageable);
		}
		return pages.getContent();
	}

//	@Override
//	public List<PartsAttributes> getPage(int start, int length, String key, String orderName, String dir) {
//		Page<PartsAttributes> pages=null;
//		Pageable pageable=new PageRequest(start/length,length,Sort.Direction.DESC,"createTime");
//		pages = partsAttributesRepository.findAll(pageable);
//		return pages.getContent();
//	}

	@Override
	public List<PartsAttributes> getPage(int start, int length,String id, String key) {
		Page<PartsAttributes> pages = null;
		Pageable pageable = new PageRequest(start/length, length, Sort.Direction.DESC, "createTime");
		pages = partsAttributesRepository.findPartsAttributes(id,key, pageable);
		return pages.getContent();
	}

	@Override
	public Long getCount(String id ,String key) {
		return partsAttributesRepository.getPartsAttributesCount(id,key);
	}

	@Override
	public List<PartsAttributes> getAllPartsAttributesByTypeid(String typeid) {
		List<PartsAttributes> pages = null;
		pages = partsAttributesRepository.findAllPartsAtrributesByTypeid(typeid);
		return pages;
	}
}
